//
//  HEMyOrderDoctorInfoCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/6.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEMyOrderDoctorInfoCell.h"

@interface HEMyOrderDoctorInfoCell ()

@property (nonatomic, strong) UILabel *titleLb;

@property (nonatomic, strong) UIImageView *logoImgView;

@property (nonatomic, strong) UILabel *nameLb;
@property (nonatomic, strong) UILabel *detialsLb;
@property (nonatomic, strong) UILabel *consulting;

@end

@implementation HEMyOrderDoctorInfoCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
     if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
         self.selectionStyle = UITableViewCellSelectionStyleNone;
         [self initUI];
     }
     return self;;
}

- (void)initUI {
    
    _titleLb = [UILabel new];
    _titleLb.font = DYBlodFont(18);
    _titleLb.text = @"医生信息";
    _titleLb.textColor = CNavLightBlackColor;
    [self.contentView addSubview:_titleLb];
    
    UIView *headLine = [UIView new];
    headLine.backgroundColor = CSplitLineColor;
    [self.contentView addSubview:headLine];
    
    [_titleLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).mas_offset(10);
        make.left.equalTo(self.contentView).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    [_titleLb setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];

    [headLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_titleLb.mas_bottom).mas_offset(10);
        make.height.mas_offset(1);
        make.left.equalTo(_titleLb);
        make.right.equalTo(_titleLb);
    }];
    
    
    // 头像
    _logoImgView = [UIImageView new];
    _logoImgView.contentMode = UIViewContentModeScaleAspectFill;
    _logoImgView.image = IMAGE_NAMED(@"address_location");
    [self.contentView addSubview:_logoImgView];
    
    _nameLb = [UILabel new];
    _nameLb.text = @"-";
    _nameLb.font = DYFont(16);
    [self.contentView addSubview:_nameLb];
    
    _detialsLb = [UILabel new];
    _detialsLb.font = DYFont(16);
    _detialsLb.textColor = CNavLightBlackColor;
    _detialsLb.text = @"-";
    _detialsLb.numberOfLines = 0;
     [self.contentView addSubview:_detialsLb];

    _consulting = [UILabel new];
    _consulting.font = DYFont(15);
    _consulting.text = @"立即咨询>>>";
    _consulting.textColor = CNavBgColor;
    _consulting.userInteractionEnabled = YES;
     [self.contentView addSubview:_consulting];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(intoPrivitChatClick)];
    [_consulting addGestureRecognizer:tap];
    
    [_logoImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headLine.mas_bottom).mas_offset(15);
        make.width.height.mas_offset(55);
        make.left.equalTo(_titleLb);
    }];
    [_logoImgView hg_setAllCornerWithCornerRadius:55 / 2.0f];

    [_nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headLine.mas_bottom).mas_offset(15);
        make.left.equalTo(_logoImgView.mas_right).mas_offset(15);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
    
    [_detialsLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_nameLb.mas_bottom).mas_offset(15);
        make.left.equalTo(_nameLb.mas_left);
        make.right.equalTo(self.contentView).mas_offset(-10);
        make.bottom.equalTo(self.contentView).mas_offset(-15);
     }];

    [_consulting mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(_logoImgView).mas_offset(-5);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
  
    HEExtraDoctorInfoModel *model = self.formModel.od_details.KdoctorInfo;
    
    if (model == nil) {
        return;
    }
    _delegate = self.formModel.proxyVC;
    if (model.order_type == HEChannelTypePrivateDoctors ||
        model.order_type == HEChannelTypePTConsultation ||
        model.order_type == HEChannelTypeDoctorTeam) {
        
        if (self.formModel.od_details.status != HEOrderStatusWaitPay &&
            self.formModel.od_details.status != HEOrderStatusClosed &&
                self.formModel.od_details.status != HEOrderStatusClosed) {
            _consulting.hidden = NO;
        }else {
            _consulting.hidden = YES;
        }
    }else {
        _consulting.hidden = YES;
    }
    
    if (self.formModel.od_details.isProxyPerson) {
        _consulting.hidden = YES;
    }
    
    if (model.order_type == HEChannelTypeDoctorTeam) {
        [_logoImgView sd_setImageWithURL:[NSURL URLWithString:model.team_info.teamIcon] placeholderImage:IMAGE_NAMED(@"defualt_icon")];
        _nameLb.text = model.team_info.teamName;
        _detialsLb.text = [NSString stringWithFormat:@"%@", model.team_info.teamHospitalName];
    }else {
        [_logoImgView sd_setImageWithURL:[NSURL URLWithString:model.doctor_info.avatar] placeholderImage:IMAGE_NAMED(@"defualt_icon")];
        _nameLb.text = model.doctor_info.realname;
        _detialsLb.text = [NSString stringWithFormat:@"%@ %@", model.doctor_info.post_name, model.doctor_info.depart_name];
    }
}

- (void)intoPrivitChatClick {
    if ([_delegate respondsToSelector:@selector(orderDocInfoCell:withExtra:)]) {
        [_delegate orderDocInfoCell:self withExtra:self.formModel.od_details.KdoctorInfo];
    }
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
